<template>
  <transition name="move">
    <div class="d-message" :class="[option.type, backTop ? 'backTop': '']" v-if="show">
      <img :src="base64Img[option.type]" alt="提示图片">
      {{ option.msg }}
    </div>
  </transition>
</template>

<script>
export default {
  name: 'DMessage',
  data () {
    return {
      option: {
        // 提示类型 success | warning | error
        type: 'success',
        // 提示文字
        msg: '',
        // 收起时间
        duration: 3000
      },
      show: false,
      backTop: false,
      // 提示类型，对应base64
      base64Img: {
        success: '',
        warning: '',
        error: ''
      }
    }
  }
}
</script>

<style scoped lang="less">
.d-message {
  position: fixed;
  left: 50%;
  padding: 0 20px;
  transform: translateX(-50%);
  z-index: 22;
  white-space: nowrap;
  height: 48px;
  display: flex;
  align-items: center;
  border: 1px solid;
  border-radius: 3px;
  box-sizing: border-box;

  &.backTop {
    top: 15px;
  }

  &.success {
    border-color: #52c41a;
    color: #52c41a;
    background: #f0f9eb;
  }

  &.warning {
    border-color: #FAAD14;
    color: #FAAD14;
    background: #f9f1eb;
  }

  &.error {
    border-color: #f5222d;
    color: #f5222d;
    background: #FEECEB;
  }

  > img {
    height: 20px;
    margin-right: 15px;
  }
}

.move-enter-active, .move-leave-active {
  top: 15px;
  transition: top .3s ease-in-out;
}

.move-enter, .move-leave-to /* .move-leave-active below version 2.1.8 */ {
  top: 0;
  opacity: 0;
}
</style>
